/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;
import DAO.Iter.ChiTietNhomDAO;
import TableModel.Chitietnhom;
import TableModel.ChitietnhomId;
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
 *
 * @author vt
 */
public class ChiTietNhomDAOImpl extends HibernateDaoSupport implements ChiTietNhomDAO{
 
    @Override
    public List<Chitietnhom> findAll() {
       return this.getHibernateTemplate().find("from Chitietnhom chitietnhom order by manhom");
    }

    @Override
    public Long add(Chitietnhom a) {
        Long result = (Long) this.getHibernateTemplate().save(a);
        return result;
    }

    @Override
    public void edit(Chitietnhom b) {
       this.getHibernateTemplate().update(b);
    }

    @Override
    public void delete(Chitietnhom c) {
       this.getHibernateTemplate().delete(c);
    }

    @Override
    public Chitietnhom getByChiTietNhom(String MaSv, String MaNhom) {
        List<Chitietnhom> list = this.getHibernateTemplate().find("from Chitietnhom chitiet where chitie.id.manhom=? and chitiet.id.masv=? ",MaSv,MaNhom);
        if(!list.isEmpty()){
            return list.get(0);
        }
        else{
            return null;
        }
    }

    @Override
    public Chitietnhom getByChiTietNhom(ChitietnhomId id) {
        return this.getHibernateTemplate().load(Chitietnhom.class, id);
    }

    @Override
    public List<String> findAllSinhVien(String MaNhom) {
        return this.getHibernateTemplate().find("from Chitietnhom chitiet where chitiet.id.manhom =?",MaNhom);
    }

    @Override
    public List<Chitietnhom> findByMaSV(String MaSV) {
        return this.getHibernateTemplate().find("from Chitietnhom chitiet where chitiet.id.masv =?",MaSV);
    }

    @Override
    public List<Chitietnhom> findByMaNhom(String maNhom) {
        return this.getHibernateTemplate().find("from Chitietnhom chitiet where chitiet.id.manhom =?",maNhom);
    }

}
